Skip to content

fix: detached docker session stays executing while container is running#137

Merged
konard merged 4 commits into
mainfrom
issue-136-cffa39dbc470
Jun 17, 2026
Merged

fix: detached docker session stays executing while container is running#137
konard merged 4 commits into
mainfrom
issue-136-cffa39dbc470

Conversation

@konard

@konard konard commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #136. A detached --isolated docker session was recorded with a terminal status (executed) and exitCode -1 while its container was still running — or not even created yet on a slow Docker-in-Docker host. This made $ --list / $ --status report the session as finished/failed when it was actually still in progress, breaking orchestrators that poll status.

Root cause

isDetachedSessionAlive (JS) / is_detached_session_alive (Rust) ran docker inspect -f '{{.State.Running}}' <name> and treated any failure (non-zero exit / empty output) as "not alive" (false). Right after docker run -d returns, the container can be transiently invisible to docker inspect on a slow DinD host. A false liveness result drove enrichDetachedStatus / enrich_detached_status to flip the record to executed and write the -1 sentinel exit code.

Fix (JS + Rust parity)

  • Distinguish "unknown" (inspect failed → null/None) from "stopped" (inspect succeeded, Running=false). When liveness is unknown, the detached session stays executing instead of fabricating a terminal -1 result.
  • Inspect now reads both {{.State.Running}} and {{.State.ExitCode}} in one call. When a container has genuinely stopped, the real exit code is resolved from the log footer first, then from docker inspect .State.ExitCode, only falling back to -1 as a last resort when no real code is available.
  • A removed/--rm container that already wrote an Exit Code: log footer still resolves to its real terminal status (footer is authoritative when liveness is unknown).

How to reproduce

  1. Start a long-running detached docker session: $ --isolated docker --detached -- sleep 30.
  2. Immediately run $ --status <session> (or $ --list) while the container is still spinning up / running.
  3. Before: status executed, exit code -1. After: status executing until the container actually exits, then the real exit code.

Tests

  • JS (js/test/session-name-status.js): added Issue #136: detached docker session liveness — unknown container → null; not-visible container keeps executing; running container stays executing; stopped container resolves the real exit code. Guarded on docker availability.
  • Rust (rust/tests/session_name_status.rs): added 4 parity tests, guarded on docker availability.
  • All JS and Rust suites pass; eslint, prettier --check, cargo fmt --check, and cargo clippy are clean.

Changelog

  • js/.changeset/detached-docker-running-status.md (start-command: patch)
  • rust/changelog.d/136.md (bump: patch)

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #136
@konard konard self-assigned this Jun 17, 2026
A detached `--isolated docker` session was recorded with a terminal
status (`executed`) and `exitCode -1` while its container was still
running (or not yet visible on a slow Docker-in-Docker host).

Root cause: `isDetachedSessionAlive`/`is_detached_session_alive` treated
a failed `docker inspect` as "not alive" (false), so
`enrichDetachedStatus`/`enrich_detached_status` marked the session
`executed` with the `-1` sentinel.

Fix (JS + Rust parity):
- Distinguish "unknown" (inspect failed -> null/None) from "stopped"
  (inspect succeeded, Running=false). Unknown liveness keeps the session
  `executing` instead of fabricating a terminal result.
- When a container has genuinely stopped, resolve the real exit code from
  the log footer, then `docker inspect .State.ExitCode`, only falling back
  to `-1` as a last resort.

Adds JS + Rust tests guarded on docker availability, plus changelog
fragments.

Closes #136
@konard konard changed the title [WIP] Detached docker session reports terminal status (executed) with exitCode -1 while container is still running fix: detached docker session stays executing while container is running Jun 17, 2026
@konard konard marked this pull request as ready for review June 17, 2026 08:06
… CI)

The stopped-container test fabricated a container with `docker run alpine`,
but on Windows runners in Windows-containers mode the Linux image never
materializes (`no matching manifest for windows`). `docker inspect` then
fails and liveness is null (unknown), not false, so the assertion broke.

- Probe with the repo's `canRunLinuxDockerImages()` instead of `docker info`,
  so the suite skips when Linux images can't run.
- Skip the stopped-container test unless the container actually exists per
  `docker inspect`.
@konard

konard commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

Working session summary

The working tree is clean (ci-logs is gitignored or already absent). Everything is complete. Let me give a final summary.

The work on issue #136 is complete and verified.

Summary

Issue #136: A detached --isolated docker session was reported with a terminal status (executed) and exitCode -1 while its container was still running — or not yet created on a slow Docker-in-Docker host — breaking orchestrators that poll $ --status / $ --list.

Root cause: isDetachedSessionAlive (JS) / is_detached_session_alive (Rust) ran docker inspect -f '{{.State.Running}}' and treated any failure as "not alive" (false). Right after docker run -d, the container can be transiently invisible to docker inspect. That false liveness drove the enrich step to flip the record to executed with the -1 sentinel.

Fix (JS + Rust parity):

  • Distinguish unknown (inspect failed → null/None) from stopped (inspect succeeded, Running=false). Unknown liveness keeps the session executing instead of fabricating a terminal result.
  • Inspect now reads {{.State.Running}} and {{.State.ExitCode}} in one call. A genuinely stopped container resolves its real exit code from the log footer, then docker inspect .State.ExitCode, only falling back to -1 as a last resort.

Tests: 4 new JS tests + 4 new Rust tests, each guarded on docker/Linux-image availability. A follow-up commit fixed a Windows-CI flake by probing with the repo's canRunLinuxDockerImages() and skipping the stopped-container test unless the container actually exists.

Verification:

  • JS suite, Rust suite (28 in the relevant file), eslint, prettier --check, cargo fmt --check, cargo clippy — all clean.
  • Both CI workflows (JavaScript + Rust) pass on the final commit 2f15524.
  • Changelog fragments added: js/.changeset/detached-docker-running-status.md and rust/changelog.d/136.md.

PR #137 is updated (title de-WIP'd, full description), marked ready for review, and MERGEABLE: #137


This summary was automatically extracted from the AI working session output.

@konard

konard commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.802376
  • Calculated by Anthropic: $6.369713
  • Difference: $0.567337 (+9.78%)

📊 Context and tokens usage:

Claude Opus 4.8: (2 sub-sessions)

  1. 116.7K / 1M (12%) input tokens, 33.1K / 128K (26%) output tokens
  2. 59.7K / 1M (6%) input tokens, 13.0K / 128K (10%) output tokens

Total: (6.2K new + 153.6K cache writes + 7.0M cache reads) input tokens, 51.7K output tokens, $5.802376 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Model: Claude Opus 4.8 (claude-opus-4-8)

📎 Log file uploaded as Gist (2980KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard konard merged commit 4326267 into main Jun 17, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detached docker session reports terminal status (executed) with exitCode -1 while container is still running

1 participant